package com.kevin.mapping.script.lexer;

import com.kevin.mapping.script.engine.JSONEnv;

import java.util.HashMap;
import java.util.Map;

public class Word extends Token {

    public static final Word TRUE = new Word(Type.BOOLEAN, "true");
    public static final Word FALSE = new Word(Type.BOOLEAN, "false");
    public static final Word BREAK = new Word(Type.BREAK, "break");
    public static final Word DO = new Word(Type.DO, "do");
    public static final Word WHILE = new Word(Type.WHILE, "while");
    public static final Word IF = new Word(Type.IF, "if");
    public static final Word ELSE = new Word(Type.ELSE, "else");
    public static final Word AND = new Word(Type.AND, "&&");
    public static final Word OR = new Word(Type.OR, "||");
    public static final Word GTE = new Word(Type.GTE, ">=");
    public static final Word GT = new Word(Type.GT, ">=");
    public static final Word LTE = new Word(Type.LTE, "<=");
    public static final Word LT = new Word(Type.LT, "<");
    public static final Word EQUAL = new Word(Type.EQUAL, "==");
    public static final Word NE = new Word(Type.NE, "!=");
    public static final Word ADD = new Word(Type.NE, "+");
    public static final Word DIV = new Word(Type.NE, "/");
    public static final Word MUL = new Word(Type.NE, "*");
    public static final Word MINUS = new Word(Type.NE, "-");


    public static final Map<String, Word> KEYWORD = new HashMap<>();

    static {
        put(Word.ADD);
        put(Word.DIV);
        put(Word.MUL);
        put(Word.MINUS);
        put(Word.TRUE);
        put(Word.FALSE);
        put(Word.BREAK);
        put(Word.DO);
        put(Word.WHILE);
        put(Word.IF);
        put(Word.ELSE);
        put(Word.AND);
        put(Word.OR);
        put(Word.GTE);
        put(Word.GT);
        put(Word.LTE);
        put(Word.LT);
        put(Word.EQUAL);
        put(Word.NE);
    }

    private String value;

    public Word(int type, String value) {
        super(type);
        this.value = value;
    }

    private static void put(Word word) {
        KEYWORD.put(word.value, word);
    }

    public String getValue(JSONEnv env) {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
